//
//  GuideViewController.m
//  RCC_Project
//
//  Created by liwenbo on 16/3/15.
//  Copyright © 2016年 liwenbo. All rights reserved.
//

#import "GuideViewController.h"
//#import "YOLoginViewController.h"
#import "BaseNavigationController.h"

#define BEGIN_BUTTON_WIDTH        130
#define BEGIN_BUTTON_HIGHT         55
@interface GuideViewController ()
@property (nonatomic, strong) NSMutableArray *imageArray;

@end

@implementation GuideViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _imageArray = [NSMutableArray arrayWithObjects:@"launchGuide1",@"launchGuide2", nil];
    [self initScrollViewsAndPageControll];
}

- (void)initScrollViewsAndPageControll {
    _guideScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kGScreenWidth, kGScreenHeight)];
    [self.view addSubview:_guideScrollView];
    _guideScrollView.delegate = self;
    _guideScrollView.pagingEnabled = YES;
    _guideScrollView.showsHorizontalScrollIndicator = NO;
    _guideScrollView.contentSize = CGSizeMake(kGScreenWidth * _imageArray.count, 0);
    _guideScrollView.directionalLockEnabled = YES;
    _guideScrollView.bounces = NO;
    
    for (int i = 0; i < _imageArray.count; i++) {
        UIImageView *backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kGScreenWidth * i, 0, kGScreenWidth, kGScreenHeight)];
        backImageView.image = [UIImage imageNamed:_imageArray[i]];
        backImageView.userInteractionEnabled = YES;
        [_guideScrollView addSubview:backImageView];
    }
    UIButton *beginOneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    beginOneButton.backgroundColor = [UIColor clearColor];
    CGFloat buttonOneWidth = kGScreenWidth;//button 宽度适配 按比例取
    CGFloat buttonOneHeight = 120.0 * KHEIGHT_6PLUS_SCALE;// button 高度适配
    beginOneButton.frame = CGRectMake(0, kGScreenHeight - 120.0 * KHEIGHT_6PLUS_SCALE, buttonOneWidth, buttonOneHeight);
    [_guideScrollView addSubview:beginOneButton];
    [beginOneButton addTarget:self action:@selector(beginOneButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *beginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    beginButton.backgroundColor = [UIColor clearColor];
    CGFloat buttonWidth = kGScreenWidth;//button 宽度适配 按比例取
    CGFloat buttonHeight = 120.0 * KHEIGHT_6PLUS_SCALE;// button 高度适配
    beginButton.frame = CGRectMake(kGScreenWidth, kGScreenHeight - 120.0 * KHEIGHT_6PLUS_SCALE, buttonWidth, buttonHeight);
    [_guideScrollView addSubview:beginButton];
    [beginButton addTarget:self action:@selector(beginButtonAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)pageControllAction:(UIPageControl *)pageCtrl {
    NSInteger pageIndex = pageCtrl.currentPage;
    CGPoint p = CGPointMake(kGScreenWidth * pageIndex , 0);
    [_guideScrollView setContentOffset:p animated:YES];
}

#pragma mark UIScrollviewDelegate
- (void)beginOneButtonAction {
    [_guideScrollView setContentOffset:CGPointMake(kGScreenWidth, 0) animated:YES];
}

- (void)beginButtonAction {
//    BaseNavigationController *rootVC = [[BaseNavigationController alloc] initWithRootViewController:[[YOLoginViewController alloc]init]];
//    [self presentViewController:rootVC animated:NO completion:nil];
}

@end
